$(document).ready(function() {

	var login = $("#login-main"), g = login.find(".login-messages");
	g.height(g.height());
	g.children().css("position", "absolute");
	var h = login.find("form");
	h.validationOptions({
		invalidHandler : function() {
			g.find(".welcome").fadeOut();
			g.find(".failure").fadeIn()
		}
	});

	$("#loading-ui").fadeOut(500);
	login.fadeIn(1000);
	var login_target_url_value = $.cookie('login_target_url');

	if (login_target_url_value) {
		$("#targetUrl").val(login_target_url_value).trigger("chosen:updated");
	}
	
	isperp.initElement("#login-main");

});

function setTargetUrlCookies(obj) {
	$.cookie('login_target_url', $(obj).val());
}